// home模块的小仓库

import { reqCategoryList, reqGetBannerList, reqFloorLists } from "@/api";

const state = {
  // state中的数据默认初始值不要瞎写，服务器返回的什么就是什么【根据接口的返回值】
  categoryList: [],
  // 轮播图
  bannerList: [],
  floorsLists: [],

};
const mutations = {
  CATEGORYLIST(state, categoryList) {
    state.categoryList = categoryList
  },
  GETBANNERLIST(state, bannerList) {
    state.bannerList = bannerList
  },
  GETFLOORLISTS(state, floorsLists) {
    state.floorsLists = floorsLists
  },
};
const actions = {
  // 通过API里面的接口调用，向服务器发送请求，获取服务器的数据
  async categoryList({ commit }) {
    let result = await reqCategoryList();
    if (result.code == 200) {
      commit('CATEGORYLIST', result.data);
    }
  },
  // 获取首页轮播图
  async getBannerList({ commit }) {
    let result = await reqGetBannerList();
    // console.log(result)
    if (result.code == 200) {
      commit('GETBANNERLIST', result.data);
    }
  },
  async getFloorLists({ commit }) {
    let result = await reqFloorLists();
    // console.log(result)
    if (result.code == 200) {
      commit('GETFLOORLISTS', result.data);
    }
  },
};
const getters = {};
export default{
  state,
  mutations,
  actions,
  getters,
}
